Representing Structs

  • There's no native struct concept — but NASM gives you two common patterns to simulate them:

  1. Manual equ  offsets (what the code uses)

    COIN_X      equ 0
    COIN_Y      equ 4
    COIN_RADIUS equ 8
    COIN_ACTIVE equ 12
    COIN_SIZE   equ 16
    
    ; Access feels like struct field access:
    movss xmm0, [coins + r14 + COIN_X]
    movss xmm1, [coins + r14 + COIN_Y]
    
  2. struc  / endstruc  — NASM's built-in macro for this

    • struc  just runs the resX  directives to compute offsets automatically — it still doesn't allocate memory.

    • To actually allocate an instance you still use .bss  or .data :

    struc Coin
        .x:      resd 1    ; 4 bytes (float)
        .y:      resd 1
        .radius: resd 1
        .active: resd 1
    endstruc
    
    ; NASM auto-generates Coin.x=0, Coin.y=4, Coin.radius=8, Coin.active=12
    ; and Coin_size=16
    
    ; Usage — identical machine code, but safer:
    movss xmm0, [coins + r14 + Coin.x]
    movss xmm1, [coins + r14 + Coin.y]